home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr13 / tstse13.zip / ROT13.S < prev    next >
Text File  |  1995-02-18  |  4KB  |  134 lines

  1. /* ROT13 rotation for SemWare's TSE editor V2.0. To make this SAL
  2.    macro operational, invoke the main menu (F10), choose "Macro",
  3.    choose "Compile" and press Enter at "Execute Macro".
  4.  
  5. ..................................................................
  6. Prof. Timo Salmi      Co-moderator of comp.archives.msdos.announce
  7. Moderating at garbo.uwasa.fi anonymous FTP archives  193.166.120.5
  8. Department of Accounting and Business Finance; University of Vaasa
  9. Internet: ts@uwasa.fi   BBS +(358)-61-3170972; FIN-65101,  Finland
  10. */
  11.  
  12. // The contents of a simple help, tied later to the CtrlAlt-H key
  13. helpdef tHelpData
  14.   title = "ROT13.S HELP"          // The help's caption
  15.   x = 10                          // Location
  16.   y = 3
  17.   // The actual help text
  18.   " Prof. Timo Salmi's ROT13"
  19.   ""
  20.   " ROT13 rotates ascii text by 13 positions. This is "
  21.   " often used as an elementary encryption technique "
  22.   " for public but somehow sensitive texts."
  23.   ""
  24.   " You can use <F11> to invoke the command menu "
  25.   " after first exiting this help. "
  26.   ""
  27.   " Last updated Sat 18-February-1995 09:43:10 "
  28. end  /* tHelpData */
  29.  
  30. // Return one character in rot13
  31. string proc timoGetRot13 (string char)
  32.   string s1[80] = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
  33.   string s2[80] = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
  34.   string rot13[1]
  35.   integer p1
  36.   p1 = Pos (char, s1)
  37.   if p1 > 0
  38.     rot13 = s2[p1]
  39.   else
  40.     rot13 = char
  41.   endif
  42.   return (rot13)
  43. end timoGetRot13
  44.  
  45. // Write a character overwriting, without advancing the cursor
  46. proc tOverText(string s)
  47.   InsertText(s,_OVERWRITE_)
  48.   PrevChar()
  49. end tOverText
  50.  
  51. // Rot13 the designated area
  52. proc timoRot13(integer choice)
  53.   string char[1]
  54.   PushPosition()
  55.   PushBlock()
  56.   case choice
  57.     // Entire file
  58.     when 1
  59.       BegFile()
  60.       repeat
  61.         if CurrChar() >= 0
  62.           char = chr(CurrChar())
  63.           tOverText(timoGetRot13(char))
  64.         endif
  65.       until not NextChar()
  66.     // Block
  67.     when 2
  68.       if not isBlockInCurrFile()
  69.         Warn('No block in current file')
  70.       elseif isBlockInCurrFile() == _COLUMN_
  71.         Warn('Column blocks not allowed for ROT13')
  72.       else
  73.         GotoBlockBegin()
  74.         if isBlockInCurrFile() == _LINE_ BegLine() endif
  75.         repeat
  76.           if CurrChar() >= 0
  77.             char = chr(CurrChar())
  78.             tOverText(timoGetRot13(char))
  79.           endif
  80.           if not NextChar() break endif
  81.           if not NextChar() break endif
  82.           if not isCursorInBlock() break endif
  83.           PrevChar()
  84.         until FALSE
  85.       endif
  86.   endcase
  87.   PopPosition()
  88.   PopBlock()
  89. end timoRot13
  90.  
  91. // New keys and menus **************************************************
  92. forward Menu tRot13Menu()
  93. forward Menu tRot13SubMenu()
  94. forward proc tDisableNewKeys()
  95.  
  96. // Add the new key definitions
  97. keydef new_keys
  98.   <CtrlAlt 5>      tRot13SubMenu()
  99.   <CtrlAlt 0>      tDisableNewKeys()
  100.   <CtrlAlt H>      QuickHelp(tHelpData)
  101.   <F11>            tRot13Menu()
  102. end
  103.  
  104. // Disabling the new extra keys ***************************************
  105. proc tDisableNewKeys()
  106.   if YesNo("Disable the extra keys:") == 1 Disable(new_keys) endif
  107. end
  108.  
  109. Menu tRot13SubMenu()
  110.   Title = "rot13"
  111.   x = 55
  112.   y = 6
  113.   history
  114.   "&Entire file", timoRot13(1)
  115.   "&Block"      , timoRot13(2)
  116. end tRot13subMenu
  117.  
  118. Menu tRot13Menu()
  119.   Title = "Timo's rot13 menu"
  120.   x = 30
  121.   y = 3
  122.   history
  123.   "&Rot13            <CtrlAlt 5>"   , tRot13SubMenu(), DontClose
  124.   "",,Divide
  125.   "Disable &new keys  <CtrlAlt 0>"   , tDisableNewKeys()
  126.   "&Help              <CtrlAlt H>"   , QuickHelp(tHelpData)
  127.   "This Menu         <F11>"
  128. end  /* tRot13Menu */
  129.  
  130. proc Main()
  131.   Enable (new_keys)
  132.   tRot13Menu()
  133. end
  134.